# -*- coding: utf-8 -*-

# pip install agentscope
from agentscope.agent import ReActAgent, UserAgent
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.model import DashScopeChatModel
from agentscope.tool import Toolkit, execute_python_code

import asyncio
import os


async def test_agentscope():
    toolkit = Toolkit()
    # toolkit.create_tool_group()

    toolkit.register_tool_function(execute_python_code)

    model = DashScopeChatModel(
        model_name="qwen-max",
        api_key=os.environ["AI_DASHSCOPE_API_KEY"],
        stream=False,
    )

    re_act_agent = ReActAgent(
        name="assistant",
        sys_prompt="",
        formatter=DashScopeChatFormatter(),
        memory=InMemoryMemory(),
        model=model,
        toolkit=toolkit,
    )

    user_agent = UserAgent(name="User")

    message = None
    while True:
        message = await re_act_agent(message)
        message = await user_agent(message)
        if message.get_text_content() == "exit":
            break

    pass


if __name__ == '__main__':
    asyncio.run(test_agentscope())
    pass
